import {useEffect,useState} from 'react'

const useScroll=()=>{
    const [position,setPositon]=useState({scrollTop:0,scrollLeft:0})
    useEffect(()=>{
        const scrollHanlde=(e)=>{
           setPositon({
            scrollTop:document.documentElement.scrollTop||document.body.scrollTop,
            scrollLeft:document.documentElement.scrollLeft||document.body.scrollLeft
           })
        }
        window.addEventListener("scroll",scrollHanlde)
        return ()=>window.removeEventListener("scroll",scrollHanlde)
    },[])
    return position
    
}
export default useScroll